package com.wpzf.zxhc.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wpzf.common.core.utils.ServletUtils;
import com.wpzf.common.core.web.domain.AjaxResult;
import com.wpzf.common.log.annotation.Log;
import com.wpzf.common.log.enums.BusinessType;
import com.wpzf.common.security.service.TokenService;
import com.wpzf.system.api.model.LoginUser;
import com.wpzf.zxhc.utils.ExcelUtils;
import com.wpzf.zxhc.domain.*;
import com.wpzf.zxhc.service.CommonService;
import com.wpzf.zxhc.service.StaticService;
import com.wpzf.zxhc.service.WpzfTbhcjgService;
import com.wpzf.zxhc.service.WpzfUnitHcTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/static")
public class StaticController {

    @Autowired
    StaticService staticService;

    @Autowired
    TokenService tokenService;


    @Log(title = "获取完成区县数量、确认图斑数量、整改图斑数量、退回区县数量", businessType = BusinessType.OTHER)
    //获取违法证明文件
    @RequestMapping(value = "/query_unit_hcqk", method = RequestMethod.POST)
    AjaxResult query_unit_hcqk(@RequestBody Map<String, Object> parms) {
        try {
            Map<String, Object> model = staticService.query_unit_hcqk(parms);
            return AjaxResult.success("获取成功", model);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取当前单位的参与人数、图斑数量、监理同意图斑数量、监理不同意图斑数量", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_and_tb", method = RequestMethod.POST)
    AjaxResult query_unit_user_and_tb(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            Map<String, Object> item = staticService.query_unit_user_and_tb(parms);
            return AjaxResult.success("获取成功", item);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取当前单位的图斑确认数量、图斑整改数量、退回图斑数量", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_count", method = RequestMethod.POST)
    AjaxResult query_unit_count(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            Map<String, Object> item = staticService.query_unit_count(parms);
            return AjaxResult.success("获取成功", item);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取评分占比", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_pf_percent", method = RequestMethod.POST)
    AjaxResult query_unit_pf_percent(@RequestBody Map<String, Object> parms) {
        try {
            Map<String, Object> model = staticService.query_unit_pf_percent(parms);
            return AjaxResult.success("获取成功", model);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取本单位核查人完成量统计", businessType = BusinessType.OTHER)
    //获取违法证明文件
    @RequestMapping(value = "/query_unit_user_hcqk", method = RequestMethod.POST)
    AjaxResult query_unit_user_hcqk(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            List<Map<String, Object>> rest = staticService.query_unit_user_hcqk(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "核查单位负责人********** 已提交区县数量、未提交区县数量、未分配区县数量、进行中的区县", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_wcqk", method = RequestMethod.POST)
    AjaxResult query_unit_wcqk(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            Map<String, Object> rest = staticService.query_unit_wcqk(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取当天本单位核查人完成量统计", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_today", method = RequestMethod.POST)
    AjaxResult query_unit_user_today(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            List<Map<String, Object>> rest = staticService.query_unit_user_today(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取本单位核查人员初次质量", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_quality", method = RequestMethod.POST)
    AjaxResult query_unit_user_quality(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            List<Map<String, Object>> rest = staticService.query_unit_user_quality(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取本单位近七天单位提交数量", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_submit_seven_days", method = RequestMethod.POST)
    AjaxResult query_unit_submit_seven_days(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            List<Map<String, Object>> rest = staticService.query_unit_submit_seven_days(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取本单位近七天单位确认数量", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_confirm_seven_days", method = RequestMethod.POST)
    AjaxResult query_unit_confirm_seven_days(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            List<Map<String, Object>> rest = staticService.query_unit_confirm_seven_days(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取本单位近七天单位整改数量", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_rectify_seven_days", method = RequestMethod.POST)
    AjaxResult query_unit_rectify_seven_days(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            List<Map<String, Object>> rest = staticService.query_unit_rectify_seven_days(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取本单位近七天不通过图斑", businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_nopass_seven_days", method = RequestMethod.POST)
    AjaxResult query_unit_nopass_seven_days(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        try {
            List<Map<String, Object>> rest = staticService.query_unit_nopass_seven_days(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }


    @Log(title = "获取监理近7天的核查情况", businessType = BusinessType.OTHER)
    //获取违法证明文件
    @RequestMapping(value = "/query_jl_hc_seven_days", method = RequestMethod.POST)
    AjaxResult query_jl_hc_seven_days(@RequestBody Map<String, Object> parms) {
        try {
            List<Map<String, Object>> rest = staticService.query_jl_hc_seven_days(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取监理完成情况", businessType = BusinessType.OTHER)
    //获取违法证明文件
    @RequestMapping(value = "/query_jl_wcqk", method = RequestMethod.POST)
    AjaxResult query_jl_wcqk(@RequestBody Map<String, Object> parms) {
        try {
            List<Map<String, Object>> rest = staticService.query_jl_wcqk(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取三家单位的基本信息", businessType = BusinessType.OTHER)
    //获取违法证明文件
    @RequestMapping(value = "/query_jl_unit_info", method = RequestMethod.POST)
    AjaxResult query_jl_unit_info(@RequestBody Map<String, Object> parms) {
        try {
            List<Map<String, Object>> rest = staticService.query_jl_unit_info(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取监理任务分配情况", businessType = BusinessType.OTHER)
    //获取违法证明文件
    @RequestMapping(value = "/query_jl_hc_info", method = RequestMethod.POST)
    AjaxResult query_jl_hc_info(@RequestBody Map<String, Object> parms) {
        try {
            List<Map<String, Object>> rest = staticService.query_jl_hc_info(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取三家单位任务完成占比", businessType = BusinessType.OTHER)
    //获取违法证明文件
    @RequestMapping(value = "/query_jl_unit_percentage", method = RequestMethod.POST)
    AjaxResult query_jl_unit_percentage(@RequestBody Map<String, Object> parms) {
        try {
            List<Map<String, Object>> rest = staticService.query_jl_unit_percentage(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title = "获取A|B|C数量", businessType = BusinessType.OTHER)
    //获取违法证明文件
    @RequestMapping(value = "/query_jl_pf_cnt", method = RequestMethod.POST)
    AjaxResult query_jl_pf_cnt(@RequestBody Map<String, Object> parms) {
        try {
            Map<String, Object> rest = staticService.query_jl_pf_cnt(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }
}
